package com.sw.haruka.model;

import com.sw.haruka.model.entity.FileShareTask;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Created by Swsbty on 2021/05/29
 */
public class FileRequestManager {

    private static FileRequestManager instance = new FileRequestManager();
    private List<DownloadObserver> observers = new CopyOnWriteArrayList<>();

    public static FileRequestManager getInstance() {
        return instance;
    }

    public void addObserver(DownloadObserver observer) {
        observers.add(observer);
    }

    public void removeObserver(DownloadObserver observer) {
        observers.remove(observer);
    }

    public void notifyStatus(List<FileShareTask> list) {
        for (DownloadObserver observer : observers) {
            observer.currentTaskList(list);
        }
    }

    public void cancelTask(int position) {
        DownloadManager.getInstance().cancelTask(position);
    }
}
